package com.swt.gap.controller;

import com.swt.gap.model.dto.SubscribeRuleDTO;
import com.swt.gap.model.dto.TaskSubscribeDTO;
import com.swt.gap.service.TaskSubscribeService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "303. 任务数据订阅")
@RestController
@RequestMapping("/task/subscribe")
@Slf4j
public class TaskSubscribeController {

    private final TaskSubscribeService taskSubscribeService;

    public TaskSubscribeController(TaskSubscribeService taskSubscribeService) {
        this.taskSubscribeService = taskSubscribeService;
    }

    @PostMapping
    @ApiOperation(value = "创建订阅", notes = "创建订阅")
    @ApiImplicitParam(name = "taskSubscribeDTO", dataType = "TaskSubscribeDTO", paramType = "body")
    @ApiResponses({@ApiResponse(code = 201, message = "创建成功")})
    public ResponseEntity<Integer> addTaskSubscribe(@RequestBody TaskSubscribeDTO taskSubscribeDTO){
        return ResponseEntity.ok(taskSubscribeService.addTaskSubscribe(taskSubscribeDTO));
    }

    @GetMapping
    @ApiOperation(value = "获取订阅", notes = "获取订阅")
    @ApiImplicitParam(name = "taskId", dataType = "int", paramType = "query")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = SubscribeRuleDTO.class, responseContainer = "List")})
    public ResponseEntity<List<SubscribeRuleDTO>> getTaskSubscribe(@RequestParam Integer taskId){
        return ResponseEntity.ok(taskSubscribeService.getTaskSubscribe(taskId));
    }

    @PutMapping
    @ApiOperation(value = "修改、删除订阅", notes = "修改订阅，删除时也是调用此接口rules不传值或空数组")
    @ApiImplicitParam(name = "taskSubscribeDTO", dataType = "TaskSubscribeDTO", paramType = "body")
    @ApiResponses({@ApiResponse(code = 200, message = "修改成功")})
    public ResponseEntity<Integer> updateTaskSubscribe(@RequestBody TaskSubscribeDTO taskSubscribeDTO){
        return ResponseEntity.ok(taskSubscribeService.updateTaskSubscribe(taskSubscribeDTO));
    }
}
